//
//  ChangeViewController.m
//  UI16.真.豆瓣
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 Amydom. All rights reserved.
//

#import "ChangeViewController.h"
#import "MovieListViewController.h"
#import "SudokuMovieLIstViewController.h"

@interface ChangeViewController ()

@property (nonatomic ,retain)MovieListViewController *movieList;
@property (nonatomic ,retain)SudokuMovieLIstViewController *SuDoList;

@property (nonatomic, assign)BOOL isSelected;


@end

@implementation ChangeViewController

-(void)dealloc{
    [_movieList release];
    [_SuDoList release];
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"电影";
    
    UIImage *rightImage = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 20);
    [button setImage:rightImage forState:UIControlStateNormal];
    // 自定义创建按钮
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
    
    // 容器视图控制器
    // 其实就是一个viewController上面放了两个或者多个viewController切换子类控制器
    self.SuDoList = [[SudokuMovieLIstViewController alloc] init];
    // 添加子视图控制器
    // 当前self作为容器视图控制器
    [self addChildViewController:self.SuDoList];
    // 然后将view添加上去
    [self.view addSubview:self.SuDoList.view];
    [_SuDoList release];
    
    self.movieList = [[MovieListViewController alloc] init];
    [self addChildViewController:self.movieList];
    [self.view addSubview:self.movieList.view];
    [_movieList release];
    
    self.isSelected = NO;

    
    
}

- (void)buttonAction:(UIButton *)button{
    
    if (YES != self.isSelected) {
        
        [UIView transitionFromView:self.movieList.view toView:self.SuDoList.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
            
        }];
        UIImage *rightImage = [UIImage imageNamed:@"btn_nav_list@2x.png"];
        rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [button setImage:rightImage forState:UIControlStateNormal];
        
    } else {
        
        [UIView transitionFromView:self.SuDoList.view toView:self.movieList.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
            
            
        }];
        UIImage *rightImage = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
        rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [button setImage:rightImage forState:UIControlStateNormal];
        
    }
    self.isSelected = !self.isSelected;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
